class CreateShoppingRecords < ActiveRecord::Migration
  def self.up
    create_table :shopping_records, :force => true do |t|
      t.references :shopping, :null => false
      t.references :shop, :null => false
      t.decimal :shopping_cost, :precision => 8, :scale => 2, :default => 0, :null => false
      t.decimal :flow_cost, :precision => 8, :scale => 2, :default => 0, :null => false
      t.decimal :unit_price, :precision => 8, :scale => 2, :default => 0, :null => false
      t.integer :number_of_people, :default => 0, :null => false
      t.decimal :people_cost, :precision => 8, :scale => 2, :default => 0, :null => false
      t.decimal :total_cost, :precision => 8, :scale => 2, :default => 0, :null => false
      t.boolean :is_checkedout, :default => false, :null => false
      t.timestamps
    end
    
    execute "alter table shopping_records
             add constraint fk_shopping_record_shopping
             foreign key (shopping_id) references shoppings(id)"
    execute "alter table shopping_records
             add constraint fk_shopping_record_shop
             foreign key (shop_id) references shops(id)"
  end
  
  def self.down
    drop_table :shopping_records
  end
end
